package models

import (
	"context"
	"git.multiverse.io/eventkit/dxc-server/constant"
	"git.multiverse.io/eventkit/kit/contexts"
)

type DxcContext struct {
	SrcOrg         string
	SrcAz          string
	SrcSu          string
	SrcInstanceId  string
	SrcEnvironment string
	SrcWorkspace   string
	SrcNodeId      string

	SpanCtx *contexts.SpanContexts
}

func DxcContextFromCtx(ctx context.Context) *DxcContext {
	dxcContext := ctx.Value(constant.DXC_CONTEXT_KEY)
	if dxcContext == nil {
		handlerContexts := contexts.HandlerContextsFromContext(ctx)
		dxcContext, _ = handlerContexts.GetAttach(constant.DXC_CONTEXT_KEY)
	}
	return dxcContext.(*DxcContext)
}

func BuildDxcContext(ctx context.Context, spanCtx *contexts.SpanContexts) context.Context {
	dxcContext := &DxcContext{
		SpanCtx: spanCtx,
	}
	return context.WithValue(ctx, constant.DXC_CONTEXT_KEY, dxcContext)
}
